package com.villaday.idf.adapter;

import android.content.Context;
import android.view.View;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.Cities_villagesEntity;
import com.villaday.idf.model.Houses_listEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;

/**
 * 首页动态列表
 */

public class BournDeticalAdapter extends AbsRecyclerViewAdapter<Houses_listEntity.BodyEntity.ListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private final String roleType;


    public BournDeticalAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_bourn_detical, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }

    @Override
    public int getItemType(Houses_listEntity.BodyEntity.ListEntity d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, Houses_listEntity.BodyEntity.ListEntity d, int position) {


        switch (d.getMyType()) {
            case 0:
                holder.bindSimpleDraweeView(R.id.sdv, d.getImageURL()+"")
                        .bindTextView(R.id.tv_title, d.getName())
                        .bindTextView(R.id.tv_des, d.getRoomNum() + "室" + d.getHallNum() + "厅" + d.getBedNum() + "床" + "  |  " + d.getAcreage() + "㎡" + "  |  " + (d.getHouseType() == 3 ? "可玩" : "宜住") + d.getPeopleNum() + "人")

                        .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)

                        .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)
                        .setViewVisible(R.id.tv_xiajia, d.isOffline()? View.VISIBLE : View.GONE)
                        .setViewVisible(R.id.tv_tuiguang, d.isOffline()? View.GONE : ("0".equals(roleType) ? View.INVISIBLE : View.VISIBLE))


                        .setClickListenerAndTag(R.id.tv_tuiguang,onClickListener,position)
                        .bindTextViewWithHtml(R.id.tv_Zhuan, "赚"+"&yen;" + (d.getBrokerage() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getBrokerage() / 100.0 + "", 2)))

                        .bindTextViewWithHtml(R.id.tv_price, "&yen;" + (d.getCurrentPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getCurrentPrice() / 100.0 + "", 0)));
                break;
            case 1:
                onAdapterCallbackListener.onCallback();
                break;
        }


    }
}
